/*
 * Copyright (C) 2014 luke.
 * 
 * This file is part of Silvie.
 * 
 * Silvie is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * Silvie is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with Silvie.  If not, see <http://www.gnu.org/licenses/>.
 */

package silvie.resources.chrmodel.chunks;

import utils.DataReader;

/**
 * AbstractChunk specialization for the "texture offsets" chunk.
 * 
 * <p>
 * Each CHR file contains a texture image which contains "subtextures". The
 * 0x7f01 chunk contains a sequence of ints that are absolute pixel coordinates
 * to each subtexture within the texture.
 * 
 * @author luke
 */
public class Chunk0x7f01 extends AbstractChunk {
	private static final int COUNT_OFFSET = 0;
	private int[] textureOffsets;

	/**
	 * Chunk0x7f01 constructor.
	 * 
	 * @see AbstractChunk#AbstractChunk(int, byte[])
	 */
	public Chunk0x7f01(int id, byte[] data) {
		super(id, data);
		this.textureOffsets = null;
	}

	@Override
	protected int decode() {
		int textureOffsetsCount = DataReader.readInt(super.data, COUNT_OFFSET);
		this.textureOffsets = new int[textureOffsetsCount];
		for (int i = 1; i <= textureOffsetsCount; i++) {
			this.textureOffsets[i - 1] = DataReader.readInt(super.data, i * DataReader.INT_SIZE);
		}
		return super.data.length;
	}

	public int[] getTextureOffsets() {
		return this.textureOffsets;
	}
}
